<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>周记实</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
		  content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
	<link rel="stylesheet" href="static/css/font.css">
	<link rel="stylesheet" href="static/css/xadmin.css">
	<script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
	<script type="text/javascript" src="static/lib/layui/layui.js"></script>
	<script type="text/javascript" src="static/js/xadmin.js"></script>
	<style type="text/css">
		.laytable-cell-1-eAccount{
			width:200px;
		}


	</style>
	<style type="text/css">
		.layui-table-cell {
			height: auto;
			line-height: 20px;
			padding: 0 15px;
			position: relative;
			overflow: hidden;
			text-overflow: ellipsis;
			box-sizing: border-box;
			white-space: nowrap;   //nowrap=不换行   normal=正常
		}
	</style>
</head>

<body class="layui-anim layui-anim-up">

<div class="x-nav">
		<span class="layui-breadcrumb"> <a>首页</a> <a>周记实</a> <a> <cite>周记实列表</cite></a>
			<!-- 在文本中添加提示信息 -->
		</span> <a class="layui-btn layui-btn-small"
				   style="line-height: 1.6em; margin-top: 3px; float: right"
				   href="javascript:location.replace(location.href);" title="刷新"> <i
		class="layui-icon" style="line-height: 30px">ဂ</i></a>
</div>

<div class="x-body" id="container">
	<div class="layui-row">
		<div class="demoTable layui-col-md10 layui-form">
			<!--
            周记实类型：
            <div class="layui-input-inline" style="width: 157px;">
                <select name="wFlag" id="wFlag" lay-filter="">
                    <option value="">请选择类型</option>
                    <option value="1">周计划</option>
                    <option value="2">临时任务</option>
                </select>
            </div>

            &nbsp&nbsp&nbsp 完成情况：
            <div class="layui-input-inline" style="width: 157px;">
                <select name="wFinshLivel" id="wFinshLivel" lay-filter="">
                    <option value="">请选择完成情况</option>
                    <option value="1">完成</option>
                    <option value="2">基本完成</option>
                    <option value="3">未完成</option>
                </select>
            </div>
            -->
			归属年份：
			<div class="layui-input-inline" style="width: 188px;">
				<select name="wYear" id="wYear" lay-filter="">
					<option value="2022" selected>2022</option>
					<option value="2023">2023</option>
					<option value="2024">2024</option>
					<option value="2025">2025</option>
					<option value="2026">2026</option>
					<option value="2027">2027</option>
					<option value="2028">2028</option>
					<option value="2029">2029</option>
					<option value="2030">2030</option>
				</select>
			</div>
			&nbsp&nbsp&nbsp
			归属月份：
			<div class="layui-input-inline" style="width: 188px;">
				<select name="wMonth" id="wMonth" lay-filter="">
					<option value="">请选择月份</option>
					<option value="01">1月份</option>
					<option value="02">2月份</option>
					<option value="03">3月份</option>
					<option value="04">4月份</option>
					<option value="05">5月份</option>
					<option value="06">6月份</option>
					<option value="07">7月份</option>
					<option value="08">8月份</option>
					<option value="09">9月份</option>
					<option value="10">10月份</option>
					<option value="11">11月份</option>
					<option value="12">12月份</option>
				</select>
			</div>
			&nbsp&nbsp&nbsp
			<button class="layui-btn" data-type="reload">搜索</button>
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			<button class="layui-btn" style="padding: 2px 10px 4px 10px"
					onclick="toAdd()">
				<i class="layui-icon"></i>添加
			</button>
			<!--
            <button class="layui-btn layui-btn-danger"
                data-type="getCheckLength" style="padding: 2px 10px 4px 10px">批量删除</button>
             -->
			&nbsp&nbsp&nbsp
			<button id="printSelect" type="button" class="layui-btn layui-btn-normal">打印</button>

		</div>


	</div>
	<!--demoTable-->
</div>

<div style="text-align: center">
	<table class="layui-table"
		   lay-data="{height: 'full-150', cellMinWidth:80, url:'empWeekInfo/findSelective.do', page:true, id:'idTest'}"
		   lay-filter="demo">
		<thead>
		<tr>
			<!--  -->
			<th lay-data="{type:'checkbox'}"></th>
			<!--
			<th
					lay-data="{field:'wAccount',templet: '<span>{{d.wAccount}}</span>', width:80, align: 'center'}">
				工号</th>
				-->
			<th
					lay-data="{field:'wName',templet: '<span>{{d.wName}}</span>', width:80, align: 'center'}">
				姓名</th>
			<!--
			<th
					lay-data="{field:'wWeekMonYear',templet: '<span>{{d.wWeekMonYear}}月份</span>', width:75, align: 'center'}">
				月数</th>
			<th
					lay-data="{field:'wWeekMonth',templet: '<span>第{{d.wWeekMonth}}周</span>', width:70, align: 'center'}">
				周数</th>
				-->
			<th
					lay-data="{field:'wWeekYear',templet: '<span>{{d.wWeekYear}}年{{d.wWeekMonYear}}月第{{d.wWeekMonth}}周</span>', width:150, align: 'center'}">
				归属周数</th>
			<th
					lay-data="{field:'wWeekInfo', templet: '<span>{{d.wWeekInfo}}</span>',width:200,align: 'left'}">
				日常工作</th>
			<th
					lay-data="{field:'wZdgzInfo', templet: '<span>{{d.wZdgzInfo}}</span>',width:200,align: 'left'}">
				重点工作</th>
			<th
					lay-data="{field:'wCxgzInfo', templet: '<span>{{d.wCxgzInfo}}</span>',width:180,align: 'left'}">
				创新工作</th>
			<th
					lay-data="{field:'wTempOraryInfo', templet: '<span>{{d.wTempOraryInfo}}</span>',width:180,align: 'left'}">
				其他事项</th>
			<!--
            <th
                lay-data="{field:'wFinshLivel',
                templet : function(d) {
                    if(d.wFinshLivel==1){
                        return '已完成';
                    }else if(d.wFinshLivel==2){
                        return '基本完成';
                    }else if(d.wFinshLivel==3){
                        return '未完成';
                    }else {
                        return '';
                    }
                },
                width:150,align: 'center'}">
                完成情况</th>
                -->
			<th
					lay-data="{field:'wCheckStatus',
						templet : function(d) {
					        if(d.wCheckStatus==0){
					            return '未审核';
					        }else if(d.wCheckStatus==1){
					            return '已审核';
					        }else {
					            return '';
					        }
					    },
						width:100,align: 'center'}">
				审核状态</th>
			<!--
			<th
					lay-data="{field:'wCreateTime', width:170, align: 'center',
						templet:function(d){return layui.util.toDateString(d.wCreateTime, 'yyyy-MM-dd HH:mm:ss');}}">
				填写时间</th>
			-->
			<th
					lay-data="{fixed: 'right', width:150, align:'center', toolbar: '#barDemo'}"></th>
		</tr>
		</thead>
	</table>
</div>

</div>
<!--
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
-->

<script type="text/html" id="barDemo">
	{{# if(d.wCheckStatus==1){}}
	<a class="layui-btn layui-btn-xs layui-btn-disabled" lay-event="edit" id="editWeekInfo">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" lay-event="del" id="delWeekInfo">删除</a>
	{{# } else if(d.wCheckStatus==0) { }}
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	{{# } else { }}
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	{{# } }}
</script>

<script>

    // add按钮的跳转函数
    function toAdd() {
        layer.confirm('每周填写一次周记实，是否了解', function (index) {
            layer.open({
                type: 2,
                area: ['98%', '98%'],
                fix: false, //不固定
                maxmin: true,
                shadeClose: true,
                shade: 0.4,
                title: '添加',
                content: 'toPage.do?url=employee/week/employeeWeekPlan-add.html'
            });
            layer.close(index);
        });
    }

    // 刷新(主要用于批量删除，不能直接在里面刷新，那样会使操作失败，要跳出来执行)
    function myReload() {
        location.replace(location.href);
    }

    /* 监听打印选中行按钮 */
    $('#printSelect').click(function() {
        layui.use(['table', 'layer'], function() {
            var table = layui.table,
                layer = layui.layer;

            var checkStatus = table.checkStatus('idTest')
            // 判断是否选中数据
            if (checkStatus.data.length === 0) {
                layer.msg('请选择周计划数据', {
                    icon: 2
                })
            } else if (checkStatus.data.length >= 2) {
                layer.msg('一次只能打印一条', {
                    icon: 2
                })
            }else {
                printSelect(checkStatus.data)
            }
        })
    })
    /*
     * [自定义打印选中行数据]
     * @param  {[type]}  allData [传入选中行]
     */
    function printSelect(allData) {

        console.log("allData="+JSON.stringify(allData));
        //用于包含内容
        var v = document.createElement("div");
        //页面头部，导入css  ，media="print"表示打印时使用该样式
        var f = ["<head>", "<style>", "div{font-size:16px;}", ".main{width:100%;height:100%}",
            ".main div{width:300px;margin-right: 50px;display:inline-block;}", "</style>", "</head>"
        ].join("");
        var contentHtml = "";
        for (let i = 0; i < allData.length; i++) {
            var data = allData[i]

            var template =

                "<div style='width:700px ;height: 700px;'>" +
                "<table width='100%' style='text-align: center'>" +
                "<tr>" +
                "<td colspan='7' style='font-size: 30px'><strong>公务员平时考核周记实表</strong><br>" +
                "</td>" +
                "</tr>" +

                "<tr>" +
                "<td colspan='7' style='font-size: 25px'>(第"+data.wWeekMonth+"周)<br>" +
                "</td>" +
                "</tr>" +

                "<tr>" +
                "<td colspan='7' style='font-size: 25px'>"+data.wWeekFirLa+"" +
                "</td>" +
                "</tr>" +

                "</table>" +
                "<table width='100%' style='text-align: left;' border='1'>" +

                "<tr style='text-align: center;'>" +
                "<td colspan='1' width='15%' height='50px;' style='font-size: 23px'><strong>姓名</strong></th>" +
                "<td colspan='2' width='25%' height='50px;' style='font-size: 23px'>" + data.wName + "</td>" +
                "<td colspan='2' width='15%' height='50px;' style='font-size: 23px'><strong>科室</strong></th>" +
                "<td colspan='2' width='25%' height='50px;' style='font-size: 23px'>" + data.wDname + "</td>" +
                "</tr>" +
                "<tr style='text-align: center;'>" +
                "<td colspan='1' width='200px;' height='50px;' style='font-size: 23px'><strong>项目</strong></td>" +
                "<td colspan='6' width='200px;' height='50px;' style='font-size: 23px'><strong>内容</strong></td>" +
                "</tr>" +

                "<tr>" +
                "<td colspan='1' width='300px;'  style='text-align: center;font-size: 20px'>日常工作</td>" +
                "<td colspan='6' >"+data.wWeekInfo+"<br>" +
                "</td>" +
                "</tr>" +
                "<tr>" +
                "<td colspan='1' width='270px;' style='text-align: center;font-size: 20px'>重要工作</td>" +
                "<td colspan='6'>"+data.wZdgzInfo+"</td>" +
                "</tr>" +

                "<tr>" +
                "<td colspan='1' width='270px;' style='text-align: center;font-size: 20px'>创新工作</td>" +
                "<td colspan='6'>"+data.wCxgzInfo+"</td>" +
                "</tr>" +
                "<tr>" +
                "<td colspan='1' width='270px;' style='text-align: center;font-size: 20px'>其他事项</td>" +
                "<td colspan='6'>"+data.wTempOraryInfo+"</td>" +
                "</tr>" +

                /**   员工自己打分是没有领导评分的**/
                "<tr>" +
                "<td colspan='1' width='300px;' height='60px;'  style='text-align: center;font-size: 20px'>本人确认签字</td>" +
                "<td colspan='6' height='88px;' style='text-align: center;'></td>" +
                "</tr>" +

                "<tr></tr>" +
                "</table>" +
                "</div>"

            contentHtml += template;
        }

        //contentHtml为已拼凑好的内容
        $(v).append(contentHtml)
        //新建窗口
        var h = window.open("打印窗口", "_blank");
        //写入拼凑内容
        h.document.write(f + $(v).prop("outerHTML"));
        //调用打印
        h.print();
        //关闭页面
        h.close();
    }

    layui.use(['form', 'util', 'layedit', 'laydate', 'table'], function () {
        var form = layui.form
            , util = layui.util
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , table = layui.table;

        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.wId + ' 的查看操作');
            } else if (obj.event === 'del') {
                if(data.wCheckStatus==1){
                    $("#delWeekInfo").attr("disabled",true);
                    layer.msg("已审核不允许操作")
                    return;
                }
                layer.confirm('确定要删除吗', function (index) {
                    $.ajax({
                        type: 'post',
                        url: 'empWeekInfo/deleteByPrimaryKey.do',
                        data: {"wId": data.wId},
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == 100) {
                                layer.msg('已删除!', {icon: 1, time: 4000});
                                obj.del();
                            }else{
                                layer.msg('删除失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            layer.alert("抱歉！出现未知错误！", {icon: 5});
                        }

                    });
                    obj.del();
                    layer.close(index);
                    // location.reload();
                });
            } else if (obj.event === 'edit') {

                if(data.wCheckStatus==1){
                    $("#editWeekInfo").attr("disabled",true);
                    layer.msg("已审核不允许操作")
                    return;
                }

                //console.log("data="+JSON.stringify(data));
                layer.open({
                    type: 2,
                    area: ['98%', '98%'],
                    fix: false, //不固定
                    maxmin: true,
                    shadeClose: true,
                    shade: 0.4,
                    title: '编辑',
                    content: 'toPage.do?url=employee/week/employeeWeekPlan-edit.html?wId=' + data.wId + '&wFinshLivel=' + data.wFinshLivel
                });
            }
        });

        var $ = layui.$, active = {

            reload: function () {
                var wFlag = $('#wFlag');
                var wFinshLivel = $('#wFinshLivel');
                var wYear = $('#wYear');
                var wMonth = $('#wMonth');

                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        w_flag: wFlag.val(),
                        w_finshLivel: wFinshLivel.val(),
                        w_Year: wYear.val(),
                        w_Month: wMonth.val()
                    }
                });
            },
            getCheckLength: function () { //获取选中数目
                var checkStatus = table.checkStatus('idTest')
                    , data = checkStatus.data;
                if(data.length<=0){
                    layer.msg("请至少选择一条数据进行操作")
                    return;
                }
                var ids = [];
                $.each(data, function (index, item) {
                    ids.push(item.wId);
                });

                layer.confirm('确定要删除吗', function (index) {

                    $.ajax({
                        type: 'post',
                        url: 'empWeekInfo/deleteByQuery.do',
                        data: {"arr": ids},
                        traditional: true,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == 100) {
                                layer.msg('已删除!', {icon: 1, time: 4000});
                            }
                            else {
                                layer.msg('删除失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            // alert("error" + data);
                            layer.alert("网路错误", {icon: 5});
                        }
                    });
                    layer.close(index);
                    relo();

                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        function relo() {
            var wFlag = $('#wFlag');
            var wFinshLivel = $('#wFinshLivel');
            // 执行重载
            table.reload('idTest', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    w_flag: wFlag.val(),
                    w_finshLivel: wFinshLivel.val()
                }
            });
        }
    })

</script>
</body>
</html>
